package com.java.project.project.activity.controller;

import java.util.List;

import com.java.project.project.activity.domain.ActivityProduct;
import com.java.project.project.activity.service.IActivityProductService;
import com.java.project.project.fulu.domain.Product;
import com.java.project.project.fulu.service.IProductService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.java.framework.aspectj.lang.annotation.Log;
import com.java.framework.aspectj.lang.enums.BusinessType;
import com.java.framework.web.controller.BaseController;
import com.java.framework.web.domain.AjaxResult;
import com.java.common.utils.poi.ExcelUtil;
import com.java.framework.web.page.TableDataInfo;

/**
 * 活动商品Controller
 * 
 * @author admin_dza
 * @date 2021-07-29
 */
@Controller
@RequestMapping("/activity/product")
public class ActivityProductController extends BaseController
{
    private String prefix = "activity/product";

    @Autowired
    private IActivityProductService activityProductService;
    @Autowired
    private IProductService productService;

    @RequiresPermissions("activity:product:view")
    @GetMapping()
    public String product()
    {
        return prefix + "/product";
    }

    /**
     * 查询活动商品列表
     */
    @RequiresPermissions("activity:product:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ActivityProduct activityProduct)
    {
        startPage();
        List<ActivityProduct> list = activityProductService.selectActivityProductList(activityProduct);
        return getDataTable(list);
    }

    /**
     * 导出活动商品列表
     */
    @RequiresPermissions("activity:product:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ActivityProduct activityProduct)
    {
        List<ActivityProduct> list = activityProductService.selectActivityProductList(activityProduct);
        ExcelUtil<ActivityProduct> util = new ExcelUtil<ActivityProduct>(ActivityProduct.class);
        return util.exportExcel(list, "product");
    }

    /**
     * 新增活动商品
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        return prefix + "/add";
    }

    /**
     * 新增保存活动商品
     */
    @RequiresPermissions("activity:product:add")
    @Log(title = "活动商品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ActivityProduct activityProduct)
    {
        return toAjax(activityProductService.insertActivityProduct(activityProduct));
    }

    /**
     * 修改活动商品
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ActivityProduct activityProduct = activityProductService.selectActivityProductById(id);
        mmap.put("activityProduct", activityProduct);
        return prefix + "/edit";
    }

    /**
     * 修改保存活动商品
     */
    @RequiresPermissions("activity:product:edit")
    @Log(title = "活动商品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ActivityProduct activityProduct)
    {
        return toAjax(activityProductService.updateActivityProduct(activityProduct));
    }

    /**
     * 删除活动商品
     */
    @RequiresPermissions("activity:product:remove")
    @Log(title = "活动商品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(activityProductService.deleteActivityProductByIds(ids));
    }

    /**
     * 新增产品
     */
//    @RequiresPermissions("weixin:coupon:list")
    @GetMapping("/selectProduct")
    public String selectProduct() {
        return prefix + "/fuluProductList";
    }

    @PostMapping("/selectProduct")
    @ResponseBody
    public TableDataInfo list(Product product) {
        startPage();
        List<Product> list = productService.selectProductList(product);
        return getDataTable(list);
    }
}
